{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = np.zeros((100, 5), dtype='bool')\n",
    "features = [\"bread\", \"milk\", \"cheese\", \"apples\", \"bananas\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(X.shape[0]):\n",
    "    if np.random.random() < 0.3:\n",
    "        # A bread winner\n",
    "        X[i][0] = 1\n",
    "        if np.random.random() < 0.5:\n",
    "            # Who likes milk\n",
    "            X[i][1] = 1\n",
    "        if np.random.random() < 0.2:\n",
    "            # Who likes cheese\n",
    "            X[i][2] = 1\n",
    "        if np.random.random() < 0.25:\n",
    "            # Who likes apples\n",
    "            X[i][3] = 1\n",
    "        if np.random.random() < 0.5:\n",
    "            # Who likes bananas\n",
    "            X[i][4] = 1\n",
    "    else:\n",
    "        # Not a bread winner\n",
    "        if np.random.random() < 0.5:\n",
    "            # Who likes milk\n",
    "            X[i][1] = 1\n",
    "            if np.random.random() < 0.2:\n",
    "                # Who likes cheese\n",
    "                X[i][2] = 1\n",
    "            if np.random.random() < 0.25:\n",
    "                # Who likes apples\n",
    "                X[i][3] = 1\n",
    "            if np.random.random() < 0.5:\n",
    "                # Who likes bananas\n",
    "                X[i][4] = 1\n",
    "        else:\n",
    "            if np.random.random() < 0.8:\n",
    "                # Who likes cheese\n",
    "                X[i][2] = 1\n",
    "            if np.random.random() < 0.6:\n",
    "                # Who likes apples\n",
    "                X[i][3] = 1\n",
    "            if np.random.random() < 0.7:\n",
    "                # Who likes bananas\n",
    "                X[i][4] = 1\n",
    "    if X[i].sum() == 0:\n",
    "        X[i][4] = 1  # Must buy something, so gets bananas\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[False False  True  True  True]\n",
      " [ True  True False  True False]\n",
      " [ True False  True  True False]\n",
      " [False False  True  True  True]\n",
      " [False  True False False  True]]\n"
     ]
    }
   ],
   "source": [
    "print(X[:5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.savetxt(\"affinity_dataset.txt\", X, fmt='%d')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  },
  "toc": {
   "colors": {
    "hover_highlight": "#DAA520",
    "navigate_num": "#000000",
    "navigate_text": "#333333",
    "running_highlight": "#FF0000",
    "selected_highlight": "#FFD700",
    "sidebar_border": "#EEEEEE",
    "wrapper_background": "#FFFFFF"
   },
   "moveMenuLeft": true,
   "nav_menu": {
    "height": "12px",
    "width": "252px"
   },
   "navigate_menu": true,
   "number_sections": true,
   "sideBar": true,
   "threshold": 4,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": false,
   "widenNotebook": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
